import { query_page } from "@/api/smart/schedul/e.js";
import mixin from "@/mixins/ICPSmixin.js";
export default {
  mixins: [mixin],
  data() {
    return {
      startTimDateEndTimDate: [],
      /*表格增删改查及下载接口*/
      loading: false,
      tableData: [
        // {
        //   sizeY: 3,
        //   produceDate: "2020-12-18 12:00:00",
        //   pouringNum: 10,
        //   type: false
        // },
        // {
        //   produceDate: "2020-12-18 12:00:00",
        //   pouringNum: 10,
        //   type: false
        // },
        // {
        //   orderNo: "日生产合计（方）：20",
        //   produceDate: "2020-12-18 12:00:00",
        //   type: true
        // },
      ],
      tableParam2: {
        page: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.getData();
  },
  methods: {
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.getData();
    },
    init() {
      this.tableParam2.engineeringName = "";
      this.tableParam2.pouringMethod = "";
      this.tableParam2.productName = "";
      this.startTimDateEndTimDate = []
      this.tableParam2.produceDate = "";
      this.tableParam2.endProduceDate = "";
      this.tableParam2.page = 1;
      this.getData();
    },
    async getData() {
      this.tableParam.page = this.tableParam2.page
      await query_page(this.tableParam).then((res) => {
        if (res.data.data.length > 0) {
          this.tableParam2.total = res.data.totalRows;
          let d = res.data.data;
          let time = "",
            sizeY = "";
          let arr = [];
          d.forEach((v, k) => {
            console.log(time);
            console.log(v.produceDate);
            console.log(time == v.produceDate, k);
            if (v.itemList.length > 0) {
              if (time != v.produceDate) {
                time = v.produceDate;
                sizeY = v.itemList.length;
              }
              let obj = {
                produceDate: time,
                sizeY: sizeY,
                type: false,
              };
              let pouringNum = 0
              v.itemList.forEach((v2, k2) => {
                pouringNum = pouringNum + v2.pouringNum
                let obj2 = {
                  orderNo: v2.orderNo,
                  productName: v2.productName,
                  pouringNum: v2.pouringNum,
                  pouringMethod: v2.pouringMethod,
                  engineeringName: v2.engineeringName,
                  k: k2
                }
                if (k2 != 0) {
                  obj.sizeY = 0
                } else {
                  obj.sizeY++
                }
                arr.push({ ...obj, ...obj2 });
                if (sizeY - 1 == k2) {
                  obj.sizeY = 0
                  //orderNo此时是合计算的值
                  obj2.orderNo = '日生产合计（方）：' + pouringNum
                  obj2.type = true;
                  obj2.k++
                  arr.push({ ...obj, ...obj2 });
                }
                if (k2 == 0) {
                  obj.sizeY = ''
                }
              });
              //orderNo这里其实是计算的合计
            }
          });
          this.tableData = arr;
          console.log(JSON.parse(JSON.stringify(this.tableData)))
          this.$nextTick(() => {
            this.$refs.table1.doLayout()
          })
        }
      });
    },
    //合并行列
    objectSpanMethod({ row, columnIndex }) {
      //第一列合并列数，被合并的要返回[0,0]
      if (row.k == 0 && columnIndex == 0) {
        return [row.sizeY, 1]
      } else if (columnIndex == 0) {
        return [0, 0]
      }
      //第二列合并行数，被合并的要返回[0,0]
      if (row.type && columnIndex == 1) {
        return [1, 5]
      } else if (row.type && columnIndex > 0) {
        return [0, 0]
      }
    },
    exportDialogFun(e) {
      this.id = e.id;
      this.exportDialog = true;
    },
  },
  filters: {
    pouringMethodFilter(e) {
      if (e) {
        e = JSON.parse(e)
        let table = e.map((res) => res.name)
        let text = table.join('、')
        return text
      }
    },
  },
};
